
* ************************************************** * 
*   APPENDIX TABLES                                  *
*                                                    *
*   Input File:    - DataAll.dta                     * 
*                  - tl_2016_us_county.dta           *
*                                                    *
*   Output File:   - Shaped_DataAll.dta              *              
* *************************************************  * 


* load the dataset:
use "DataAll.dta", clear



** TABLE A1: TOTAL ANCESTRY **

	* TABLE A1 Model 1 
reg reppercent2016 German_ancestry_share2016 American_ancestry_share2016 English_ancestry_share2016 Irish_ancestry_share2016 Italian_ancestry_share2016 NoCollegeDegree IncomeDiffToNatMedianIncome dummy_american_south2016
	* TABLE A1 Model 2 
reg dempercent2016 German_ancestry_share2016 American_ancestry_share2016 English_ancestry_share2016  Irish_ancestry_share2016 Italian_ancestry_share2016 NoCollegeDegree IncomeDiffToNatMedianIncome dummy_american_south2016
	* TABLE A1 Model 3 
reg DiffRepDem2016 German_ancestry_share2016 American_ancestry_share2016 English_ancestry_share2016  Irish_ancestry_share2016 Italian_ancestry_share2016 NoCollegeDegree IncomeDiffToNatMedianIncome dummy_american_south2016
	* TABLE A1 Model 4 
reg DiffRepRep20162012 German_ancestry_share2016 American_ancestry_share2016 English_ancestry_share2016  Irish_ancestry_share2016 Italian_ancestry_share2016 NoCollegeDegree IncomeDiffToNatMedianIncome dummy_american_south2016
	* TABLE A1 Model 5  
reg DifDifRepRep German_ancestry_share2016 American_ancestry_share2016 English_ancestry_share2016 Irish_ancestry_share2016 Italian_ancestry_share2016 NoCollegeDegree IncomeDiffToNatMedianIncome dummy_american_south2016


 ******************************************************************************
 ******************************************************************************
 
 
** TABLE A2: TOTAL ANCESTRY ** 

	* TABLE A2 Model 6
logit swing_state_dummy2016 German_ancestry_share2016 American_ancestry_share2016 English_ancestry_share2016 Irish_ancestry_share2016 Italian_ancestry_share2016 NoCollegeDegree IncomeDiffToNatMedianIncome dummy_american_south2016


 ******************************************************************************
 ******************************************************************************

 
** TABLE A3: Replication of Table 1 with German birthplace data **

	* TABLE A3 Model 1
reg reppercent2016 GermanBirthPlace1910 American_share_single2016 English_share_single2016 Irish_share_single2016 Italian_share_single2016 NoCollegeDegree IncomeDiffToNatMedianIncome dummy_american_south2016 
	* TABLE A3 Model 2
reg dempercent2016 GermanBirthPlace1910 American_share_single2016 English_share_single2016 Irish_share_single2016 Italian_share_single2016 NoCollegeDegree IncomeDiffToNatMedianIncome dummy_american_south2016
	* TABLE A3 Model 3
reg DiffRepDem2016 GermanBirthPlace1910 American_share_single2016 English_share_single2016 Irish_share_single2016 Italian_share_single2016 NoCollegeDegree IncomeDiffToNatMedianIncome dummy_american_south2016


 ******************************************************************************
 ******************************************************************************
	
	
** TABLE A4: ROSS PEROT **

	* TABLE A4 
reg otherpercent1992 German_share_single1992 American_share_single1992 English_share_single1992 Irish_share_single1992 Italian_share_single1992 dummy_american_south1992


 ******************************************************************************
 ******************************************************************************
	
	
** TABLE A5 ** 	
		 
	* Spatial regressions *

*** 1) Shape-files unserer geographischen Daten finden *** 
*** 2) Translate the downloaded file to Stata format ***

* syntax from:  https://www.stata.com/manuals15/spintro7.pdf#spintro7:

// ---------------------------------------------------------- 
// [SP] intro 4, step 2: Translate the shapefile

spshape2dta tl_2016_us_county // perform the shape 

// ----------------------------------------------------------
// [SP] intro 4, step 3: Look at the data

use tl_2016_us_county, clear
describe
		  
list in 1/2

// ----------------------------------------------------------
// [SP] intro 4, step 4: Create standard ID variable
          
generate long fips = real(STATEFP + COUNTYFP)
bysort fips: assert _N==1
assert fips != .
          
// ----------------------------------------------------------
// [SP] intro 4, step 5: Tell Sp to use standard ID variable
          
spset fips, modify replace

// ----------------------------------------------------------
// [SP] intro 4, step 6: Set coordinate units
          
spset, modify coordsys(latlong, miles)

save, replace	 // save the changes	


		  
**************************************************************************		


*** 3) Merge shape file to our data ***

* our relevant datasets: 1) DataAll.dta 

* 1) DataAll.dta 
use "DataAll.dta", clear 

describe

*************************************
** Check for any repeated observation
duplicates report fips 
duplicates list fips 
drop if fips == . // drop duplicates 

merge 1:1 fips using "tl_2016_us_county.dta"		
			
keep if _merge==3 
drop _merge		

save "Shaped_DataAll.dta", replace // saves our original data file	



**************************************************************************	
	
		
*** 4) (re-) Analyze our regressions ***
	* - run original OLS on merged data set
	* - Create W matrix as follows: - spmatrix create contiguity W -
	* - Run Moran’s I test : - estat moran, errorlag(W) -		


* 1) Shaped_DataAll
use "Shaped_DataAll.dta", clear

sum reppercent2016 // 3,111
sum German_share_single2016 // 3,111
sum American_share_single2016 // 3,111
sum English_share_single2016 // 3,111
sum Irish_share_single2016 // 3,111
sum Italian_share_single2016 // 3,111
sum NoCollegeDegree // 3,111 
sum IncomeDiffToNatMedianIncome // 3,110
sum dummy_american_south2016 // 3,111

drop if IncomeDiffToNatMedianIncome == . // needs to be dropped because one county is missing but disenables the generation of the spatial matrix

spmatrix clear // needed for calculating the next spatial matrix	

* calculate the spatial matrix: 
spmatrix create contiguity W


	* MODEL 1
* orginal model
reg reppercent2016 German_share_single2016 American_share_single2016 English_share_single2016 Irish_share_single2016 Italian_share_single2016 NoCollegeDegree IncomeDiffToNatMedianIncome dummy_american_south2016

* check moran I
estat moran, errorlag(W)

* TABLE A5 Model 1
spregress reppercent2016 German_share_single2016 American_share_single2016 English_share_single2016 Irish_share_single2016 Italian_share_single2016 NoCollegeDegree IncomeDiffToNatMedianIncome dummy_american_south2016, gs2sls errorlag(W)



	* MODEL 2	
* orginal model
reg dempercent2016 German_share_single2016 American_share_single2016 English_share_single2016 Irish_share_single2016 Italian_share_single2016 NoCollegeDegree IncomeDiffToNatMedianIncome dummy_american_south2016

* check moran I
estat moran, errorlag(W)

* TABLE A5 Model 2
spregress dempercent2016 German_share_single2016 American_share_single2016 English_share_single2016 Irish_share_single2016 Italian_share_single2016 NoCollegeDegree IncomeDiffToNatMedianIncome dummy_american_south2016, gs2sls errorlag(W)

		 
	
	* MODEL 3	
* orginal model
reg DiffRepDem2016 German_share_single2016 American_share_single2016 English_share_single2016 Irish_share_single2016 Italian_share_single2016 NoCollegeDegree IncomeDiffToNatMedianIncome dummy_american_south2016		
	
* check moran I
estat moran, errorlag(W)

* TABLE A5 Model 3
spregress DiffRepDem2016 German_share_single2016 American_share_single2016 English_share_single2016 Irish_share_single2016 Italian_share_single2016 NoCollegeDegree IncomeDiffToNatMedianIncome dummy_american_south2016, gs2sls errorlag(W)



	* MODEL 4
* orginal model
regress DiffRepRep20162012 German_share_single2016 American_share_single2016 English_share_single2016 Irish_share_single2016 Italian_share_single2016 NoCollegeDegree IncomeDiffToNatMedianIncome dummy_american_south2016

* check moran I
estat moran, errorlag(W)

* TABLE A5 Model 4
spregress DiffRepRep20162012 German_share_single2016 American_share_single2016 English_share_single2016 Irish_share_single2016 Italian_share_single2016 NoCollegeDegree IncomeDiffToNatMedianIncome dummy_american_south2016, gs2sls errorlag(W)



	* MODEL 5
* orginal model
regress DifDifRepRep German_share_single2016 American_share_single2016 English_share_single2016 Irish_share_single2016 Italian_share_single2016 NoCollegeDegree IncomeDiffToNatMedianIncome dummy_american_south2016	

* check moran I
estat moran, errorlag(W)

* TABLE A5 Model 5
spregress DifDifRepRep German_share_single2016 American_share_single2016 English_share_single2016 Irish_share_single2016 Italian_share_single2016 NoCollegeDegree IncomeDiffToNatMedianIncome dummy_american_south2016, gs2sls errorlag(W)

spmatrix clear // needed for calculating the next spatial matrix	

***************************************************************************

* reload the dataset to use the complete dataset and not the reduced one:
use "Shaped_DataAll.dta", clear


drop if reppercent2016 == . | REP1920 == . | American_share_single2016 == . | English_share_single2016 == . | Irish_share_single2016 == . | Italian_share_single2016 == . | NoCollegeDegree == . | IncomeDiffToNatMedianIncome == . | dummy_american_south2016 == . // those osbervations with missings need to be dropped because missings disenable the generation of the spatial matrix

* calculate the spatial matrix: 
spmatrix create contiguity W


	* MODEL 11
* orginal model
reg reppercent2016 REP1920 American_share_single2016 English_share_single2016 Irish_share_single2016 Italian_share_single2016 NoCollegeDegree IncomeDiffToNatMedianIncome dummy_american_south2016

* check moran I
estat moran, errorlag(W)

* TABLE A5 Model 11
spregress reppercent2016 REP1920 American_share_single2016 English_share_single2016 Irish_share_single2016 Italian_share_single2016 NoCollegeDegree IncomeDiffToNatMedianIncome dummy_american_south2016, gs2sls errorlag(W)


		
	* MODEL 12
* orginal model
reg reppercent2016 REP1920 German_share_single2016 American_share_single2016 English_share_single2016 Irish_share_single2016 Italian_share_single2016 NoCollegeDegree IncomeDiffToNatMedianIncome dummy_american_south2016

* check moran I
estat moran, errorlag(W)

* TABLE A5 Model 12
spregress reppercent2016 REP1920 German_share_single2016 American_share_single2016 English_share_single2016 Irish_share_single2016 Italian_share_single2016 NoCollegeDegree IncomeDiffToNatMedianIncome dummy_american_south2016, gs2sls errorlag(W)




************************************* END **************************************



